package cn.information.utils;

import java.sql.Connection;

public class DButil {
    public static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String URL = "jdbc:mysql://localhost:3306/fp?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "ljw20040915.";

    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName(DRIVER);
            conn = java.sql.DriverManager.getConnection(URL, USERNAME, PASSWORD);
            System.out.println("数据库连接成功");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
    public static void close(Connection conn) {
        if(conn!=null){
            try {
                conn.close();
                System.out.println("数据库连接关闭");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
